<?php
function save_schedule($userid,$lesson_index,$lesson_name,$startweek,$endweek){
	if($startweek==''||$endweek==''){
		$query="INSERT INTO schedule(USERID,LESSONINDEX,LESSONNAME) VALUES($userid,'$lesson_index','$lesson_name')";
	}else{
		$query="INSERT INTO schedule(USERID,LESSONINDEX,LESSONNAME,STARTWEEK,ENDWEEK) VALUES($userid,'$lesson_index','$lesson_name',$startweek,$endweek)";
	}
	mysql_query($query);
	return ;
}
function update_schedule($userid,$lesson_index,$lesson_name,$startweek,$endweek){
	if($startweek==''||$endweek==''){
		$query="UPDATE schedule SET LESSONNAME='$lesson_name',STARTWEEK=NULL,ENDWEEK=NULL WHERE USERID=$userid AND LESSONINDEX='$lesson_index'";
	}else{
		$query="UPDATE schedule SET LESSONNAME='$lesson_name',STARTWEEK=$startweek,ENDWEEK=$endweek WHERE USERID=$userid AND LESSONINDEX='$lesson_index'";
	}
	mysql_query($query);
	return ;
}
function get_schedule($userid,$lesson_index){
	$query="SELECT LESSONNAME,STARTWEEK,ENDWEEK FROM schedule WHERE USERID=$userid AND LESSONINDEX='$lesson_index'";
	$result=mysql_query($query);
	return $result;
}
?>